package ide.ccf.ccproject.perspective;

import org.eclipse.cdt.internal.ui.wizards.CWizardRegistry;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.ui.IFolderLayout;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;
import org.eclipse.ui.console.IConsoleConstants;
import org.eclipse.ui.navigator.resources.ProjectExplorer;

/**
 * CCF C++透视图
 *
 */
@SuppressWarnings("restriction")
public class PerspectiveFactory implements IPerspectiveFactory 
{
	private static final String perspectiveId = "ide.ccf.ccproject.Perspective";
	
	/**
	 * 构造器	
	 */
	public PerspectiveFactory() 
	{
		super();
	}

	/**
	 * 获取透视图ID
	 * @return
	 */
	public static String getPerspectiveId() 
	{
		return perspectiveId;
	}
	
	/**
	 * 创建透视图初始化布局
	 * @see IPerspectiveFactory#createInitialLayout
	 */
	@SuppressWarnings("deprecation")
	public void createInitialLayout(IPageLayout layout) 
	{
 		String editorArea = layout.getEditorArea();
		
		IFolderLayout folder1= layout.createFolder("topLeft", IPageLayout.LEFT, (float)0.25, editorArea); //$NON-NLS-1$
		folder1.addView(ProjectExplorer.VIEW_ID);
		folder1.addPlaceholder(IPageLayout.ID_RES_NAV);
		folder1.addPlaceholder(IPageLayout.ID_BOOKMARKS);
		folder1.addView("ide.ccf.ccdesigner.views.widgetboxview");
		
		IFolderLayout folder2 = layout.createFolder("bottom", IPageLayout.BOTTOM, (float)0.75, editorArea); //$NON-NLS-1$
		folder2.addView(IPageLayout.ID_PROBLEM_VIEW);
		folder2.addView(IConsoleConstants.ID_CONSOLE_VIEW);
		folder2.addView(IPageLayout.ID_TASK_LIST);
		
		folder2.addView(CUIPlugin.ID_INCLUDE_BROWSER);
		folder2.addView(CUIPlugin.ID_CALL_HIERARCHY);
		folder2.addView(CUIPlugin.ID_TYPE_HIERARCHY);
		folder2.addView("org.eclipse.cdt.debug.ui.executablesView");

		folder2.addView("ide.ccf.ccdesigner.views.actioneditorview");
		folder2.addView("ide.ccf.ccdesigner.views.Q_SIGNALSloteditorview");
		
		IFolderLayout folder3= layout.createFolder("topRight", IPageLayout.RIGHT,(float)0.75, editorArea); //$NON-NLS-1$
		folder3.addView(IPageLayout.ID_OUTLINE);
		folder3.addView("ide.ccf.ccdesigner.views.propertyeditorview");
		folder3.addView("ide.ccf.ccdesigner.views.objectinspectorview");

		layout.addActionSet(CUIPlugin.SEARCH_ACTION_SET_ID);
		layout.addActionSet(CUIPlugin.ID_CELEMENT_CREATION_ACTION_SET);
		layout.addActionSet(IPageLayout.ID_NAVIGATE_ACTION_SET);
		
		layout.addShowViewShortcut(IConsoleConstants.ID_CONSOLE_VIEW);
		layout.addShowViewShortcut(NewSearchUI.SEARCH_VIEW_ID);

		layout.addShowViewShortcut(IPageLayout.ID_OUTLINE);
		layout.addShowViewShortcut(IPageLayout.ID_PROBLEM_VIEW);
		layout.addShowViewShortcut(ProjectExplorer.VIEW_ID);
		layout.addShowViewShortcut(IPageLayout.ID_RES_NAV);
		layout.addShowViewShortcut(IPageLayout.ID_PROP_SHEET);

		layout.addShowInPart(ProjectExplorer.VIEW_ID);
		layout.addShowInPart(IPageLayout.ID_RES_NAV);
		
		addCWizardShortcuts(layout);
	}
	
	/**
	 * 添加C向导快捷入口
	 * @param layout
	 */
	private void addCWizardShortcuts(IPageLayout layout) 
	{
		// C项目向导
		String[] wizIDs = CWizardRegistry.getProjectWizardIDs();
		
		for (int i = 0; i < wizIDs.length; ++i) 
		{
			layout.addNewWizardShortcut(wizIDs[i]);
		}
		
		// C文件夹向导
		wizIDs = CWizardRegistry.getFolderWizardIDs();
		
		for (int i = 0; i < wizIDs.length; ++i) 
		{
			layout.addNewWizardShortcut(wizIDs[i]);
		}
		
		// C文件向导
		wizIDs = CWizardRegistry.getFileWizardIDs();
		
		for (int i = 0; i < wizIDs.length; ++i) 
		{
			layout.addNewWizardShortcut(wizIDs[i]);
		}
		
		// C类型向导
		wizIDs = CWizardRegistry.getTypeWizardIDs();
		for (int i = 0; i < wizIDs.length; ++i) 
		{
			layout.addNewWizardShortcut(wizIDs[i]);
		}
	}
}
